/*****************************************************************************
*
*  PROJECT:     SlipStream
*               (CVector2 - 2D Vector Class)
*  LICENSE:     GNU General Public License v3 - http://www.gnu.org/licenses/gpl.html

*  DEVELOPERS:  Philip Farquharson	<B00137077@studentmail.uws.ac.uk>
*				John Gray			<B00145524@studentmail.uws.ac.uk>		
*				Zohaib Bhatti		<B00104280@studentmail.uws.ac.uk>
*				Euan Hislop			<B00138636@studentmail.uws.ac.uk>
*
*****************************************************************************/

#include "CVector2.h"

// comparison
bool CVector2::operator== ( CVector2& vec)
{
	return (x == vec.x && y == vec.y);
}

// negation
CVector2 CVector2::operator- ()
{
	return CVector2(0-x, 0-y);
}

// assignment
const CVector2& CVector2::operator= ( const CVector2& vec )
{
	x = vec.x;
	y = vec.y;
	return *this;
}

// addition
const CVector2& CVector2::operator+= ( const CVector2& vec )
{
	x += vec.x;
	y += vec.y;
	return *this;
}
	
// subtraction
const CVector2& CVector2::operator-= ( const CVector2& vec)
{
	x -= vec.x;
	y -= vec.y;
	return *this;
}

// scaling up
const CVector2& CVector2::operator*= ( const float& fScale )
{
	x *= fScale;
	y *= fScale;
	return *this;
}

// scaling down
const CVector2& CVector2::operator/= ( const float& fScale )
{
	x /= fScale;
	y /= fScale;
	return *this;
}
	
// addition w/o modification
const CVector2 CVector2::operator+ ( const CVector2& vec ) const
{
	return CVector2(x+vec.x, y+vec.y);
}
	
// subtract w/o modification
const CVector2 CVector2::operator- ( const CVector2& vec ) const
{
	return CVector2(x-vec.x, y-vec.y);
}

// scaling up w/o modification
const CVector2 CVector2::operator* ( const float& fScale ) const
{
	return CVector2(x*fScale, y*fScale);
}

// scaling down w/o modification
const CVector2 CVector2::operator/ ( const float& fScale ) const
{
	return CVector2(x/fScale, y/fScale);
}

// dot product
const float CVector2::dot ( const CVector2& vec ) const
{
	return (x*vec.x, y*vec.y);
}
	
// vector length
const float CVector2::length() const
{
	return ( sqrt(x*x + y*y) );
}
	
// unit vector
const CVector2 CVector2::unit() const
{
	float fTemp = length();
	return CVector2(x/fTemp, y/fTemp);
}

// normalize - make this vector a unit vector
void CVector2::normalize ( void )
{
	float fTemp = length();
	x /= fTemp;
	y /= fTemp;
}

// update this vector
void CVector2::update ( const CVector2& vec )
{
	x = vec.x;
	y = vec.y;
}

void CVector2::update ( float fX, float fY )
{
	x = fX;
	y = fY;
}